import request from '@/utils/request'
import type {
  Member,
  CreateMemberRequest,
  UpdateMemberRequest,
  MemberListResponse
} from '@/types/api/member'
import type { BaseResponse, PaginationResponse } from '@/types/common/response'

/**
 * 会员管理相关API
 */
export const memberApi = {
  /**
   * 获取会员列表
   * @param params 查询参数
   */
  getMemberList(params: { page: number; pageSize: number; keyword?: string }) {
    return request.get<BaseResponse<PaginationResponse<Member>>>('/members', { params })
  },

  /**
   * 获取会员详情
   * @param id 会员ID
   */
  getMemberDetail(id: number) {
    return request.get<BaseResponse<Member>>(`/members/${id}`)
  },

  /**
   * 创建会员
   * @param data 会员信息
   */
  createMember(data: CreateMemberRequest) {
    return request.post<BaseResponse<null>>('/members', data)
  },

  /**
   * 更新会员
   * @param id 会员ID
   * @param data 会员信息
   */
  updateMember(id: number, data: UpdateMemberRequest) {
    return request.put<BaseResponse<null>>(`/members/${id}`, data)
  },

  /**
   * 删除会员
   * @param id 会员ID
   */
  deleteMember(id: number) {
    return request.delete<BaseResponse<null>>(`/members/${id}`)
  }
}
